package cn.iocoder.aics.module.member.service.shareinfo;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import cn.iocoder.aics.module.member.controller.admin.shareinfo.vo.*;
import cn.iocoder.aics.module.member.dal.dataobject.shareinfo.ShareInfoDO;
import cn.iocoder.aics.framework.common.pojo.PageResult;
import cn.iocoder.aics.framework.common.util.object.BeanUtils;

import cn.iocoder.aics.module.member.dal.mysql.shareinfo.ShareInfoMapper;

import static cn.iocoder.aics.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 分享数据 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ShareInfoServiceImpl implements ShareInfoService {

    @Resource
    private ShareInfoMapper shareInfoMapper;

    @Override
    public Long createShareInfo(ShareInfoSaveReqVO createReqVO) {
        // 插入
        ShareInfoDO shareInfo = BeanUtils.toBean(createReqVO, ShareInfoDO.class);
        shareInfoMapper.insert(shareInfo);
        // 返回
        return shareInfo.getId();
    }

    @Override
    public void updateShareInfo(ShareInfoSaveReqVO updateReqVO) {
        // 校验存在
        validateShareInfoExists(updateReqVO.getId());
        // 更新
        ShareInfoDO updateObj = BeanUtils.toBean(updateReqVO, ShareInfoDO.class);
        shareInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteShareInfo(Long id) {
        // 校验存在
        validateShareInfoExists(id);
        // 删除
        shareInfoMapper.deleteById(id);
    }

    private void validateShareInfoExists(Long id) {
//        if (shareInfoMapper.selectById(id) == null) {
//            throw exception(SHARE_INFO_NOT_EXISTS);
//        }
    }

    @Override
    public ShareInfoDO getShareInfo(Long id) {
        return shareInfoMapper.selectById(id);
    }

    @Override
    public PageResult<ShareInfoDO> getShareInfoPage(ShareInfoPageReqVO pageReqVO) {
        return shareInfoMapper.selectPage(pageReqVO);
    }

}